package fun.chutianshu.eescore_full.service.impl;

import fun.chutianshu.eescore_full.entity.Homework;
import fun.chutianshu.eescore_full.dao.HomeworkDao;
import fun.chutianshu.eescore_full.service.HomeworkService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 作业表(Homework)表服务实现类
 *
 * @author makejava
 * @since 2021-04-27 20:07:12
 */
@Service("homeworkService")
public class HomeworkServiceImpl implements HomeworkService {
    @Resource
    private HomeworkDao homeworkDao;

    /**
     * 通过ID查询单条数据
     *
     * @param homeworkId 主键
     * @return 实例对象
     */
    @Override
    public Homework queryById(Long homeworkId) {
        return this.homeworkDao.queryById(homeworkId);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit 查询条数
     * @return 对象列表
     */
    @Override
    public List<Homework> queryAllByLimit(int offset, int limit) {
        return this.homeworkDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param homework 实例对象
     * @return 实例对象
     */
    @Override
    public Homework insert(Homework homework) {
        this.homeworkDao.insert(homework);
        return homework;
    }

    /**
     * 修改数据
     *
     * @param homework 实例对象
     * @return 实例对象
     */
    @Override
    public Homework update(Homework homework) {
        this.homeworkDao.update(homework);
        return this.queryById(homework.getHomeworkId());
    }

    /**
     * 通过主键删除数据
     *
     * @param homeworkId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long homeworkId) {
        return this.homeworkDao.deleteById(homeworkId) > 0;
    }
}